﻿using System;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using NetTopologySuite.Features;

namespace Observer
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建几何
            Geometry geometry = new Point(new Coordinate(100.87, 23.22));

            // 创建属性
            IAttributesTable attributes = new AttributesTable();
            attributes.Add("Name", "301食堂");

            // 创建要素
            IFeature feature = new Feature(geometry, attributes);
            Console.WriteLine("要素Geometry为：" + feature.Geometry.ToText());
            Console.WriteLine("要素Attribute为：" + feature.Attributes["Name"].ToString());

            // 创建主题
            ISubject subject = new FeatureSubject
            {
                Feature = feature
            };

            // 创建观察者并注册
            IObserver attributeObserver = new AttributeViewObserver();
            IObserver geometryObserver = new MapCanvasObserver();
            subject.Attach(attributeObserver);
            subject.Attach(geometryObserver);

            // 修改要素属性，并通知观察者
            feature.Attributes["Name"] = "302食堂";
            subject.ChangeStatus = ChangeStatus.ATTRIBUTE;
            subject.Notify();

            // 修改要素几何，并通知观察者
            feature.Geometry = new Point(new Coordinate(120.31, 11.54));
            subject.ChangeStatus = ChangeStatus.GEOMETRY;
            subject.Notify();

            Console.ReadLine();
        }
    }
}